/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Thing;

import java.util.Random;
import java.util.Vector;


/**
 *
 * @author THINH
 */
public abstract class Gift extends Thing{
    //field
    protected int healthbonus;
    protected int healthcover;
    protected int armorbonus;
    protected int damage;
    protected int typeOfGift;
    protected String path;
    protected boolean lock = false;
    private Character owner;
    Random r = new Random();
    
    //constructor
    public Gift(){
        super();
        
    }
    public Gift(String pathImage, int frameWidth, int frameHeight, int[]frameSequence,Character t){
        super(pathImage, frameWidth, frameHeight, frameSequence);
        owner = t;
        RandomAttr();
        path = pathImage;
    }
    //main func
    public void update(){
        //code here
        
        super.update();        
    }
    
    //func
    public void Active(){
        System.out.println("active ne");
        owner.MAX_HEALTH += healthbonus;
        owner.currenthealth += healthcover;
        if(owner.currenthealth > owner.MAX_HEALTH)
            owner.currenthealth = owner.MAX_HEALTH;
        owner.damagebonus += damage;
        owner.armor += armorbonus; 
    }
    
    public static int Random(int a,int b)
    {
        Random ran = new Random();
        while (true) {
            int result = ran.nextInt() % b;
            if (result >= a) {
                return result;
            }
        }
    }
    
    private void RandomAttr()
    {
        int[] attr = {0,0,0,0};
        int i = 0;
        while(i < 4)
        {
            int a = Random(0,100);
            if(Check(attr,a))
            {
                attr[i] = a;
                i++;
            }
        }
        healthbonus = attr[0];
        healthcover = attr[1];
        damage = attr[2];
        armorbonus = attr[3];
    }
    
    private boolean Check(int[] number,int x)
    {
        if (number != null) {
            for (int i = 0; i < number.length; i++) {
                if (x == number[i]) {
                    return false;
                }
            }
        }
        return true;
    }
    
    public int TypeGift()
    {
        return typeOfGift;
    }
    
    public String getPath()
    {
        return path;
    }
}
